package com.woniuxy.joylife.manager.controller;

import com.woniuxy.common.utils.KeyUtil;
import com.woniuxy.joylife.manager.entity.RoomEntity;
import com.woniuxy.joylife.manager.service.RoomService;
import com.woniuxy.joylife.manager.utils.PageUtils;
import com.woniuxy.joylife.manager.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 门牌号
 *
 * @author renxiang
 * @email 981405195@qq.com
 * @date 2020-05-13 02:47:54
 */
@RestController
@RequestMapping("manager/room")
public class RoomController {
    @Autowired
    private RoomService roomService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("manager:room:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = roomService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{roomId}")
    //@RequiresPermissions("manager:room:info")
    public R info(@PathVariable("roomId") String roomId){
		RoomEntity room = roomService.getById(roomId);

        return R.ok().put("room", room);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("manager:room:save")
    public R save(@RequestBody RoomEntity room) throws Exception {
        room.setRoomId(KeyUtil.generateKey());
        if(!roomService.saveRoomEntity(room)){
            throw new Exception("插入失败，重复插入");
        }
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("manager:room:update")
    public R update(@RequestBody RoomEntity room){
		roomService.updateById(room);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("manager:room:delete")
    public R delete(@RequestBody String[] roomIds){
		roomService.removeByIds(Arrays.asList(roomIds));

        return R.ok();
    }

}
